home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / as03.arc / PRNT.ASM < prev    next >
Assembly Source File  |  1984-10-19  |  14KB  |  523 lines

  1.       PAGE   60,132
  2. ;  prnt.ASM   06/25/84 update 10/16/84 sas
  3. ;  Subroutine called by a basic program to print a string .
  4. ;
  5. COLOR    EQU    0B800H        ;seg address of color adaptor memory
  6. MONO    EQU    0B000H        ;seg address of color adaptor memory
  7. CRTCA    EQU    3D4h        ;port address of 6845 crt controller addr reg
  8. CRTCD    EQU    3D5h        ;port address of 6845 crt controller data reg
  9. CRTSTAT EQU    03DAh        ;crt status port address
  10. VSYNC    EQU    08h        ;crt vertical retrace status bit map
  11. PORTB    EQU    61h        ;I/O Port B
  12. MAG_NUM EQU    10110110b    ;special number for port B initialize
  13. TIME_2A EQU    43h        ;timer 2
  14. TIME_2B EQU    42h        ;timer 2
  15. TONE_CH EQU    1200d        ;frequency of tone to use
  16. ;
  17. DGROUP    GROUP    DATASEG
  18. DATASEG SEGMENT PARA PUBLIC 'DATA'
  19. FUNCT    DB    ?        ;function number
  20. FG_COLR DB    ?        ;forground color
  21. BG_COLR DB    ?        ;backround color
  22. T_FORG    DW    ?        ;forground color of field on entry
  23. T_BACK    DW    ?        ;backround color of field on entry
  24. ROW    DB    ?        ;upper left row
  25. COL    DB    ?        ;upper left column
  26. LENG    DW    ?        ;length of string
  27. STRG_AD DW    ?        ;address of string in DS
  28. STRING    DW    256 DUP(00)
  29. ATTRIB    DB    ?        ;attribute byte to use
  30. REPTC    DW    1        ;number of times to repeat each character
  31. REPTWD    DB    1        ;number of times to repeat each string
  32. ER_DUR    DW    500d
  33. DATASEG ENDS
  34. ;
  35. CSEG    SEGMENT 'CODE'
  36.     ASSUME    CS:CSEG
  37.     PUBLIC    PRNT
  38. PRNT    PROC    FAR
  39.     PUSH    BP        ;BP unknown (don't care)
  40.     MOV    BP,SP        ;set base for parm list
  41.     PUSH    DS        ;DS -> basic work area
  42.     PUSH    ES        ;ES -> basic work area
  43.     MOV    AX,DATASEG    ;establish data addressability
  44.     MOV    DS,AX        ;now DS -> my data
  45.     ASSUME    DS:DATASEG
  46. ;
  47. ; get the integer function number,string length,and string address from
  48. ; the call. the string address is in the extra segment.
  49. ;
  50.     PUSH    BP
  51.     MOV    SI,SS:[BP+6]    ;get addr of parameter
  52.     MOV    AL,ES:[SI]    ;get value of parm
  53.     MOV    FUNCT,AL
  54.     MOV    SI,SS:[BP+8]    ;get addr of parameter
  55.     MOV    AX,ES:[SI]    ;get value of parm
  56.     MOV    LENG,AX
  57.     MOV    AX,ES:[SI+2]    ;get value of parm
  58.     MOV    STRG_AD,AX
  59.  
  60. ;
  61. ;   repeat function
  62. ;   check for character & string repitition -1 through -80 & -81 through -160
  63. ;
  64.     MOV    REPTC,1     ;set char repeat to 1
  65.     MOV    REPTWD,1    ;set string repeat to 1
  66.     CMP    FUNCT,0     ;are you requesting function repeat function
  67.     JGE    TYP1        ;if => 0 then check for function 1
  68.     NEG    FUNCT        ;convert the negitive function to positive
  69.     CMP    FUNCT,80d    ;are you requesting a repeat string function
  70.     JG    WD_REP        ;if yes the goto repeat string code
  71. ;
  72.     XOR    AX,AX
  73.     MOV    AL,FUNCT    ;move the number of repeat character to
  74.     MOV    REPTC,AX    ;  the repeat character indicator
  75.     JMP    WD_OUT        ;jump out of block
  76. ;
  77. WD_REP: SUB    FUNCT,80d    ;subtract 80 from value
  78.     MOV    AL,FUNCT    ;set number of times to repeat the string
  79.     MOV    REPTWD,AL    ;    in repeat string variable
  80. WD_OUT: MOV    FUNCT,3     ;force function to 3
  81. ;
  82. ;   function 1 send only color use current value for row & col
  83. ;
  84. TYP1:    CMP    FUNCT,1     ;are you requesting function 1?
  85.     JNE    TYP2        ;if not check for function 2
  86.     MOV    SI,SS:[BP+10]    ;get addr of parameter
  87.     MOV    AL,ES:[SI]    ;get value of parm
  88.     MOV    FG_COLR,AL
  89.     MOV    SI,SS:[BP+12]    ;get addr of parameter
  90.     MOV    AL,ES:[SI]    ;get value of parm
  91.     MOV    BG_COLR,AL
  92.     CALL    GET_ATB     ;convert fg,bg to attribute byte
  93. ;
  94. ;  function 2 & 4 send row & col no colors  use current value for color
  95. ;     function 4 for read string/ function 2 reg print
  96. ;
  97. TYP2:    CMP    FUNCT,2     ;are you requesting function 2?
  98.     JE    R0        ;if yes then get row,col
  99.     CMP    FUNCT,4     ;are you requesting function 3
  100.     JNE    TYP3
  101. R0:    MOV    SI,SS:[BP+10]    ;get addr of parameter
  102.     MOV    AL,ES:[SI]    ;get value of parm
  103.     CMP    AL,0        ;if value sent for row is 0 then use current
  104.     JE    R1        ;  value for row
  105.     SUB    AL,1
  106.     MOV    ROW,AL
  107. R1:    MOV    SI,SS:[BP+12]    ;get addr of parameter
  108.     MOV    AL,ES:[SI]    ;get value of parm
  109.     CMP    AL,0        ;if value for col is 0 then use current value
  110.     JE    R2        ;   for col
  111.     SUB    AL,1
  112.     MOV    COL,AL
  113. R2:
  114. ;
  115. ;    function 3 send row,col and color/ full data print all prams specified.
  116. ;
  117. TYP3:    CMP    FUNCT,7
  118.     JE    R2A
  119.     CMP    FUNCT,6
  120.     JE    R2A
  121.     CMP    FUNCT,3
  122.     JNE    TYP5
  123. R2A:    MOV    SI,SS:[BP+10]    ;get addr of parameter
  124.     MOV    AL,ES:[SI]    ;get value of parm
  125.     CMP    AL,0
  126.     JE    R3
  127.     SUB    AL,1
  128.     MOV    ROW,AL
  129. R3:    MOV    SI,SS:[BP+12]    ;get addr of parameter
  130.     MOV    AX,ES:[SI]    ;get value of parm
  131.     CMP    AX,0
  132.     JE    R4
  133.     CMP    FUNCT,6
  134.     JNE    R3A
  135.     MOV    ER_DUR,AX
  136.     JMP    R4
  137. R3A:    SUB    AL,1
  138.     MOV    COL,AL
  139. R4:    MOV    SI,SS:[BP+14]    ;get addr of parameter
  140.     MOV    AL,ES:[SI]    ;get value of parm
  141.     MOV    FG_COLR,AL
  142.     MOV    SI,SS:[BP+16]    ;get addr of parameter
  143.     MOV    AL,ES:[SI]    ;get value of parm
  144.     MOV    BG_COLR,AL
  145.     CALL    GET_ATB
  146. ;
  147. ;    function 5,6 send row and color for center and for 6 tone
  148. ;      5 - center / 6 - error
  149. ;
  150. TYP5:    CMP    FUNCT,5
  151.     JNE    CAL_IT
  152. T5A:    MOV    SI,SS:[BP+10]    ;get addr of parameter
  153.     MOV    AL,ES:[SI]    ;get value of parm
  154.     CMP    AL,0
  155.     JE    T5B
  156.     SUB    AL,1
  157.     MOV    ROW,AL
  158. T5B:    MOV    SI,SS:[BP+12]    ;get addr of parameter
  159.     MOV    AL,ES:[SI]    ;get value of parm
  160.     MOV    FG_COLR,AL
  161.     MOV    SI,SS:[BP+14]    ;get addr of parameter
  162.     MOV    AL,ES:[SI]    ;get value of parm
  163.     MOV    BG_COLR,AL
  164.     CALL    GET_ATB
  165. ;
  166. ;   set up address of string form basica and my data area string
  167. ;
  168. CAL_IT:
  169.     MOV    SI,[STRG_AD]    ;set address of string in si
  170.     LEA    DI,STRING    ;load address of my data area string
  171.     MOV    CX,LENG     ;set loop counter to length of string
  172.     MOV    AH,ATTRIB    ;set color attribute
  173. ;
  174. ;   check for null string
  175. ;
  176.     MOV    AL,ES:[SI]    ;move character to al
  177.     CMP    AL,00        ;is the character a null
  178.     JE    FINISH        ;if yes then return
  179.     CMP    CX,0        ;is the length 0
  180.     JE    FINISH        ;if yes then return
  181. ;
  182. ;   move string from basic data area to my data area
  183. ;
  184. MOV_STR:MOV    AL,ES:[SI]    ;move character from basic to al
  185.     MOV    DS:[DI],AX    ;move character/attribute to my data area
  186.     INC    SI
  187.     INC    DI
  188.     INC    DI
  189.     LOOP    MOV_STR
  190. ;
  191. ;
  192. ;  determine if color or mono adaptor, and set ES to adaptor's address
  193.     CALL    VIDEO
  194. ;
  195. ;              --- calls for function 5 ---
  196. ;
  197.     CMP    FUNCT,5
  198.     JNE    F6
  199.     CALL    CENT        ;find center of line
  200.     CALL    GET_CR        ;find offset into video buffer
  201.     CALL    PT_STG        ;print the string
  202.     JMP    FINISH
  203. ;
  204. ;              --- calls for function 6 ---
  205. ;
  206. F6:    CMP    FUNCT,6
  207.     JNE    FOUT
  208.     CALL    CENT        ;find center of line
  209.     CALL    GET_CR        ;find offset into video buffer
  210.     CALL    PT_STG        ;print the string
  211.     CALL    ERR        ;make tone at speaker
  212.     MOV    CX,ER_DUR    ;set duration of display
  213. F6A:    PUSH    CX        ;loop the print cycle for the number
  214.     CALL    GET_CR        ;   of cycles in the duration
  215.     CALL    PT_STG
  216.     POP    CX
  217.     LOOP    F6A
  218. ;            blank the string
  219.     LEA    DI,STRING    ;get address of the string
  220.     MOV    CX,LENG     ;set length
  221. BLANK:    MOV    AX,DS:[DI]    ;mov char/attrib to ax
  222.     MOV    AL,32        ;mov blank to cahr part
  223.     MOV    DS:[DI],AX    ;store it
  224.     INC    DI
  225.     INC    DI
  226.     LOOP    BLANK
  227.     CALL    GET_CR        ;get offset into video buffer
  228.     CALL    PT_STG        ;clear the error message
  229.     JMP    FINISH
  230. ;
  231. ;        ---------- calls for all other functions ---------
  232. ;
  233. FOUT:    CALL    GET_CR
  234.     CMP    FUNCT,4
  235.     JNE    C1
  236.     CALL    RD_STG
  237.     JMP    FINISH
  238. ;
  239. C1:    CMP    FUNCT,7
  240.     JNE    C2
  241.     CALL    GET_CLR
  242. ;
  243. C2:    CALL    PT_STG
  244. ;
  245. ;      get correct return numbers
  246. ;
  247. FINISH: POP    BP
  248.     CMP    FUNCT,0
  249.     JE    RET4
  250. ;
  251. ;
  252.     CMP    FUNCT,1
  253.     JE    RET8
  254. ;
  255.     CMP    FUNCT,2
  256.     JE    RET8
  257. ;
  258.     CMP    FUNCT,3
  259.     JE    RET12
  260. ;
  261.     CMP    FUNCT,4
  262.     JE    RET8A
  263. ;
  264.     CMP    FUNCT,5
  265.     JE    RET10
  266. ;
  267.     CMP    FUNCT,6
  268.     JE    RET10
  269. ;
  270.     CMP    FUNCT,7
  271.     JE    RET12A
  272. ;
  273. ;
  274. RET4:    POP    ES
  275.     POP    DS
  276.     POP    BP
  277.     RET    4        ;return to basic
  278. ;
  279. RET8:    POP    ES
  280.     POP    DS
  281.     POP    BP
  282.     RET    8        ;return to basic
  283. ;
  284. ;           function 5 passing the string back to basic.
  285. ;
  286. RET8A:    POP    ES        ;get back basic es
  287.     MOV    SI,[STRG_AD]    ;get address of basic string
  288.     LEA    DI,STRING    ;get address of my string
  289.     MOV    CX,LENG     ;get length of string
  290. RESET:    MOV    AX,DS:[DI]    ;move char of my string to ax
  291.     MOV    ES:[SI],AX    ;move ax to basic string
  292.     INC    SI
  293.     INC    DI
  294.     LOOP    RESET
  295.     POP    DS
  296.     POP    BP
  297.     RET    8        ;return to basic
  298. ;
  299. RET10:    POP    ES
  300.     POP    DS
  301.     POP    BP
  302.     RET    10        ;return to basic
  303. ;
  304. RET12:    POP    ES
  305.     POP    DS
  306.     POP    BP
  307.     RET    12        ;return to basic
  308.  
  309. RET12A:
  310.     POP    ES
  311.     MOV    AX,T_FORG    ;get addr of parameter
  312.     MOV    SI,SS:[BP+14]    ;get addr of parameter
  313.     MOV    ES:[SI],AX    ;get value of parm
  314.     MOV    AX,T_BACK    ;get addr of parameter
  315.     MOV    SI,SS:[BP+16]    ;get addr of parameter
  316.     MOV    ES:[SI],AX    ;get value of parm
  317.     POP    DS
  318.     POP    BP
  319.     RET    12        ;return to basic
  320. PRNT    ENDP
  321. ;
  322. ;--------------------------------------------------------------------
  323. ;    PRINT CHARACTER STRING AT ROW,COL WITH FG,BG COLORS
  324. ;
  325. PT_STG    PROC    NEAR
  326.     XOR    CX,CX
  327.     MOV    CL,REPTWD    ;set up loop counter for repeat word
  328. NXT_WD: PUSH    CX        ;save count
  329.     MOV    CX,LENG     ;set up count for number of characters in string
  330.     LEA    DI,STRING    ;load address of my string
  331. ;
  332. ;    wait until vertical retrace
  333. ;
  334.     MOV    DX,CRTSTAT
  335. CRETRC: IN    AL,DX
  336.     TEST    AL,VSYNC
  337.     JZ    CRETRC
  338. ;
  339. NXT_CHR:PUSH    CX        ;save character count
  340.     MOV    BX,DS:[DI]    ;move character from string to bx
  341.     MOV    CX,REPTC    ;set up count for repeat character
  342. REP_CHR:MOV    ES:[SI],BX    ;move character to video buffer
  343.     INC    SI
  344.     INC    SI
  345.     LOOP    REP_CHR     ;loop to repeat character
  346.     INC    DI
  347.     INC    DI
  348.     POP    CX        ;restore character count
  349.     LOOP    NXT_CHR     ;loop for next character
  350.     POP    CX        ;restore count for repeat string
  351.     LOOP    NXT_WD        ;loop to repeat the string
  352.     RET
  353. PT_STG    ENDP
  354. ;---------------------------------------------------------------------
  355. ;---------------------------------------------------------------------
  356. ;    READ IN CHARACTERS FROM SCREEN
  357. ;
  358. RD_STG    PROC    NEAR
  359.     LEA    DI,STRING    ;set address of string in si
  360.     MOV    CX,LENG     ;set loop counter to length of string
  361. ;
  362. RD_LIN:
  363.     MOV    AX,ES:[SI]    ;move character/attribute from video buffer to ax
  364.     MOV    DS:[DI],AL    ;move character to my data area
  365.     INC    DI
  366.     INC    SI
  367.     INC    SI
  368.     LOOP    RD_LIN        ;loop to next character
  369.     RET
  370. RD_STG    ENDP
  371. ;---------------------------------------------------------------------
  372. GET_ATB PROC    NEAR
  373.     MOV    AL,FG_COLR    ;move foreground color to bx
  374.     MOV    AH,BG_COLR    ;move backround color to bx
  375.     CMP    AL,15        ;check for color > 15 ie blinking
  376.     JG    BLNK        ;if > 15 then set blink bit
  377.     AND    AL,15        ;set normal fg color
  378.     JMP    N_BLNK        ;
  379. BLNK:    OR    AL,128        ;set blink bit 7
  380.     AND    AL,143        ;zero out bit 6,5,4 used for backround
  381. N_BLNK: AND    AH,7        ;zero out bit 7,6,5,4,3 used for forground
  382.     MOV    CL,4        ;4 bit shift count
  383.     SHL    AH,CL        ;shift right 3 bits to pos 6,5,4
  384.     OR    AL,AH        ;combine for & back to form attribute byte
  385.     MOV    ATTRIB,AL    ;move it to STORAGE
  386.     RET
  387. GET_ATB ENDP
  388. ;---------------------------------------------------------------------
  389. ;
  390. ;  compute starting offset into display buffer
  391. ;
  392. GET_CR    PROC    NEAR
  393.     XOR    AX,AX
  394.     MOV    AL,ROW        ;move starting row to al
  395.     MOV    BX,160        ;move number of character/row to bx
  396.     MUL    BX        ;multiply by 160
  397.     XOR    CX,CX
  398.     MOV    CL,COL        ;move starting column number to cl
  399.     ADD    AX,CX        ;add (scol * 2) to get relative offset
  400.     ADD    AX,CX
  401.     MOV    SI,AX        ;SI offsets VIDEO buffers
  402.     RET
  403. GET_CR    ENDP
  404. ;---------------------------------------------------------------------
  405. ;
  406. ;  determine if color or mono adaptor, and set ES to adaptor's address
  407. ;
  408. VIDEO    PROC    NEAR
  409.     PUSH    DS        ;save DS -> my data
  410.     MOV    AX,0        ;set up data seg register ..
  411.     MOV    DS,AX        ;..to gain access to DOS info
  412.     MOV    SI,410H     ;offset to color/mono byte
  413.     MOV    AL,[SI]     ;fetch byte
  414.     POP    DS        ;restore DS -> my data
  415.     AND    AL,48        ;mask
  416.     CMP    AL,48        ;48=mono, 32=color
  417.     JZ    SETMNO
  418.     MOV    AX,COLOR    ;add seg addr of page 0
  419.     JMP    SETES
  420. SETMNO: MOV    AX,MONO
  421. SETES:    MOV    ES,AX        ;now ES -> adaptor memory
  422.     RET
  423. VIDEO    ENDP
  424. ;---------------------------------------------------------------------
  425. ;   calculate column for centering a stripped string
  426. ;
  427. CENT    PROC    NEAR
  428. ;
  429. ;    find number of leading blanks
  430. ;
  431.     XOR    CX,CX        ;zero out CX
  432.     LEA    DI,STRING    ;load address of string
  433. C_R0:    CMP    CX,LENG     ;are you at end of string
  434.     JE    C_R2        ;if yes then out
  435.     MOV    AX,DS:[DI]    ;load character to ax
  436.     CMP    AL,20H        ;is it a blank
  437.     JNE    C_R2        ;if not a blank then out
  438.     INC    CX        ;index 1
  439.     INC    DI        ;index 2
  440.     INC    DI
  441.     JMP    C_R0        ;loop it
  442. ;
  443. ;    find number of trailing blanks
  444. ;
  445. C_R2:    PUSH    CX        ;save number of blanks on stack
  446.     LEA    DI,STRING    ;load address of string
  447.     ADD    DI,LENG     ;add length to address
  448.     ADD    DI,LENG     ;add length to address
  449.     SUB    DI,2        ;index back 2
  450.     XOR    CX,CX        ;zero CX
  451. C_R3:    MOV    AX,DS:[DI]    ;move character to AX
  452.     CMP    AL,20H        ;is it a blank
  453.     JNE    C_R4        ;if not then out
  454.     INC    CX        ;add 1 ti cx
  455.     DEC    DI        ;move back one character
  456.     DEC    DI
  457.     JMP    C_R3        ;loop it
  458. ;
  459. ;    calculate column position for centering
  460. ;    column = ((80-(length-trail-lead))/2)-lead
  461. ;
  462. C_R4:    MOV    AX,LENG     ;load length
  463.     SUB    AX,CX        ;subtract number of trailing blanks
  464.     POP    CX        ;get number of leading blanks
  465.     SUB    AX,CX        ;subtract number of leading blanks
  466.     MOV    BX,80        ;load screen width
  467.     SUB    BX,AX        ;subtract out adjusted length
  468.     SAR    BX,1        ;divide by 2
  469.     SUB    BX,CX        ;subtract number of leading blanks
  470.     MOV    COL,BL        ;set column
  471.     RET
  472. CENT    ENDP
  473. ;-----------------------------------------------------------------------
  474. ;        error tone for speaker
  475. ERR    PROC    NEAR
  476. ;     tone control of speaker
  477.     MOV    AL,MAG_NUM    ;put magic number
  478.     OUT    TIME_2A,AL    ;    into timer2
  479. ;
  480. ;     the constant put in ax changes the pitch
  481. ;
  482. TONE:    MOV    AX,TONE_CH    ;move 1/pitch into ax
  483.     OUT    TIME_2B,AL    ;LSB into timer2
  484.     MOV    AL,AH        ;MSB to AL then
  485.     OUT    TIME_2B,AL    ;  to timer2
  486. ;
  487.     IN    AL,PORTB    ;read port B into AL
  488.     MOV    AH,AL        ;save original in AH
  489.     OR    AL,3        ;turn on bits 0 and 1
  490.     OUT    PORTB,AL    ;turn on speaker
  491. ;
  492.     SUB    CX,CX        ;set up loop count
  493. WAIT:    LOOP    WAIT        ;delay
  494. ;
  495.     MOV    AL,AH
  496.     OUT    PORTB,AL    ;turn off speaker
  497.  ;
  498.     RET
  499.  
  500. ERR    ENDP
  501. ;---------------------------------------------------------------------
  502. ;---------------------------------------------------------------------
  503. GET_CLR PROC    NEAR
  504.     LEA    DI,STRING
  505.     MOV    AX,ES:[SI]    ;get attribute of fist character in field
  506.     XOR    BX,BX        ;blank BX registor
  507.     MOV    BL,AH        ;move attribute to the BL register
  508.     AND    BL,15        ;mask out the backround and blink bit
  509.     CMP    AH,128        ;is this a blink character
  510.     JGE    N_BLK        ;if no then go to no blink
  511.     ADD    BX,16        ;add 16 to forground color
  512. N_BLK:    MOV    T_FORG,BX    ;move completed forground color to temp data
  513.     MOV    BL,AH        ;move attribute to bl
  514.     AND    BL,112        ;mask out forground and blink bit
  515.     MOV    CL,4        ;4 bit shift count
  516.     SHR    BL,CL        ;shift right 3 bits to pos 2,1,0
  517.     MOV    T_BACK,BX    ;move backround to temp data
  518.     RET
  519. GET_CLR ENDP
  520. ;---------------------------------------------------------------------
  521. CSEG    ENDS
  522.     END
  523.